package com.myprojects.authenticationservice.controller;

//import com.example.permissionservice.pojo.UserWithRole;

import com.myprojects.common.dto.Msg;

import com.myprojects.common.pojo.User;
import com.myprojects.common.pojo.UserWithRole;
import com.myprojects.authenticationservice.service.FeignAuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class AuthenticationController {

    @Autowired
    FeignAuthenticationService feignAuthenticationService;

    /**
     * 该方法用于使用用户信息来登录
     */
    @RequestMapping(value = "/login-by-info",method = RequestMethod.POST)
    @ResponseBody
    public Msg loginByUser( @RequestBody UserWithRole user){
        return feignAuthenticationService.loginByUser(user);
    }

    /**
     * 该方法用于使用用户信息来注册
     */
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    @ResponseBody
    public Msg register( @RequestBody UserWithRole user ){
        return feignAuthenticationService.register(user);
    }

    /**
     * 该方法用于检查用户注册的信息
     */
    @RequestMapping(value = "/register",method = RequestMethod.PUT)
    @ResponseBody
    public Msg checkRegister(@RequestBody UserWithRole user ){
        return feignAuthenticationService.checkRegister(user);
    }


    /**
     * 该方法用于修改密码
     */
    @RequestMapping(value = "/password",method = RequestMethod.POST)
    @ResponseBody
    public Msg updatePassword(@RequestHeader("accessToken") String accessToken, @RequestBody UserWithRole user){
        return feignAuthenticationService.updatePassword(accessToken,user);
    }

    /**
     * 该方法用于检查修改密码
     */
    @RequestMapping(value = "/password",method = RequestMethod.PUT)
    @ResponseBody
    public Msg checkUpdatePassword( @RequestBody UserWithRole user){
        return feignAuthenticationService.checkUpdatePassword(user);
    }

    /**
     * 该方法用于使用用户token来注销登录
     */
    @RequestMapping(value = "/logout-by-token",method = RequestMethod.POST)
    @ResponseBody
    public Msg logoutByToken(@RequestHeader("accessToken") String accessToken) {
        return feignAuthenticationService.logoutByToken(accessToken);
    }

}
